package cn.ratel.db;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Page<T> implements Serializable {
	private List<T> list;
	private int pageNumber;
	private int pageSize;
	private int totalPage;
	private int totalRow;

	public Page(List<T> list, int pageNumber, int pageSize, int totalRow) {
		this.list = list;
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		if (totalRow % pageSize == 0) {
			this.totalPage = totalRow / pageSize;
		} else {
			this.totalPage = totalRow / pageSize + 1;
		}
		this.totalRow = totalRow;
	}

	public Page(int pageNumber, int rows) {
		this.pageNumber = pageNumber;
		this.pageSize = 1;
		this.totalPage = rows;
		this.totalRow = rows;
	}

	public List<T> getList() {
		return list == null ? new ArrayList<>(0) : list;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public int getTotalRow() {
		return totalRow;
	}

	@Override
	public String toString() {
		return "Page{" +
				"list=" + list +
				", pageNumber=" + pageNumber +
				", pageSize=" + pageSize +
				", totalPage=" + totalPage +
				", totalRow=" + totalRow +
				'}';
	}
}

